set(OPENCV_DIR "/home/cmy/web/opencv")

cmake_minimum_required( VERSION 3.8 )
project( main )

set(CMAKE_CXX_STANDARD 17)

add_library(sha1_shared STATIC utils/sha1.cpp)

# Needed for opencv2/opencv.hpp
# include_directories("${OPENCV_DIR}/include")

# Needed by opencv.hpp for opencv2/opencv_modules.hpp
# include_directories("${OPENCV_DIR}/build_wasm")

# Needed by emscripten
include_directories( /home/cmy/web/emsdk/upstream/emscripten/cache/sysroot/include )

set(OpenCV_DIR "/home/cmy/web/opencv/build_wasm")
find_package(OpenCV  REQUIRED)

# Needed by opencv_modules.hpp for every module
# file( GLOB opencv_include_modules "${OPENCV_DIR}/modules/*/include" )
# include_directories( ${opencv_include_modules} )


# Our hello world executable
add_executable( main main.cpp)

set(CMAKE_EXECUTABLE_SUFFIX ".js") # 编译生成.html

# Link to opencv.js precompiled libraries
# file( GLOB opencv_libs "${OPENCV_DIR}/build_wasm/lib/*.a" )
# target_link_libraries( main ${opencv_libs} )

target_link_libraries(main sha1_shared)

target_link_libraries(main ${OpenCV_LIBS})


# # 查找 OpenSSL 库
# find_package(OpenSSL REQUIRED)
# include_directories(${OPENSSL_INCLUDE_DIR})
# target_link_libraries(main ${OPENSSL_LIBRARIES})

set_target_properties( main PROPERTIES LINK_FLAGS " -lembind -sFETCH -sSINGLE_FILE -sENVIRONMENT='worker' -sALLOW_MEMORY_GROWTH -sNO_DISABLE_EXCEPTION_CATCHING -O3")

# -s MODULARIZE=1 -s EXPORT_NAME=CUtils
# 导出模块。在JS中的调用方式：
# const mod = await CUtils({})
# mod.asmGamma()

# -sSINGLE_FILE
# 把wasm文件转为base64字符串，放进js中

# -sENVIRONMENT='worker'
